package com.ruoyi.project.system.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.SysCexpense;
import com.ruoyi.project.system.domain.SysRexpense;
import com.ruoyi.project.system.service.SysCexpeService;
import com.ruoyi.project.system.service.SysRexpeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author :sxt
 * @dote :21:38 2021/7/16
 */
@RestController
@RequestMapping("/system/rexpense")
public class SysRexpeController extends BaseController {

    @Autowired
    private SysRexpeService sysRexpeService;

    /**
     * 分页查询挂号费用信息
     * @param sysRexpense  可以根据相应信息模糊查询
     * @return    返回查询到的挂号费用信息集合
     */
    @PreAuthorize("@ss.hasPermi('system:rexpense:query')")
    @GetMapping("/getList")
    public TableDataInfo getList(SysRexpense sysRexpense){
        //分页相关
        startPage();
        List<SysRexpense>list=sysRexpeService.getList(sysRexpense);
        return getDataTable(list);
    }


    /**
     * 根据指定ID查询检查项目费用信息
     * @param srId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:rexpense:query')")
    @GetMapping("/getReById/{srId}")
    public AjaxResult getReById(@PathVariable Integer srId){
        SysRexpense sysRexpense=sysRexpeService.getReById(srId);
        return AjaxResult.success(sysRexpense);
    }

    /**
     * 增加检查项目信息
     * @param sysRexpense
     * @return
     */
    @Transactional
    @PreAuthorize("@ss.hasPermi('system:rexpense:add')")
    @PostMapping("/add")
    public AjaxResult addRexpense(@RequestBody SysRexpense sysRexpense){
        sysRexpense.setCreateBy(SecurityUtils.getUsername());
        sysRexpense.setCreateTime(new Date());
        int row=sysRexpeService.addRexpense(sysRexpense);
        return toAjax(row);
    }

    /**
     * 修改检查项目信息
     * @param sysRexpense
     * @return
     */
    @Transactional
    @PreAuthorize("@ss.hasPermi('system:rexpense:edit')")
    @PutMapping("/update")
    public AjaxResult updateRexpense(@RequestBody SysRexpense sysRexpense){
        sysRexpense.setUpdateBy(SecurityUtils.getUsername());
        sysRexpense.setUpdateTime(new Date());
        int row=sysRexpeService.updateRexpense(sysRexpense);
        return toAjax(row);
    }


    /**
     * 删除检查费用信息
     * @param srIds  是要删除的记录的id，是个数组，支持批量删除
     * @return
     */
    @Transactional
    @PreAuthorize("@ss.hasPermi('system:rexpense:remove')")
    @DeleteMapping("/remove/{srIds}")
    public AjaxResult delRexpense(@PathVariable Integer [] srIds){
        int row=sysRexpeService.removeRexpense(srIds);
        return toAjax(row);
    }


}
